package com.hl.sfzy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hl.sfzy.constant.CommonConstant;
import com.hl.sfzy.entity.SysCourseOrders;
import com.hl.sfzy.mapper.SysCourseOrdersMapper;
import com.hl.sfzy.service.SysCourseOrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ffc
 * @version 1.0
 * @description: TODO
 * @className: SysCourseOrdersServiceImpl
 * @date 2024/7/12 21:09
 */

@Service("sysCourseOrdersService")
public class SysCourseOrdersServiceImpl implements SysCourseOrdersService {
    @Autowired
    SysCourseOrdersMapper sysCourseOrdersMapper;

    @Override
    public int add(SysCourseOrders entity) {
        return sysCourseOrdersMapper.insert(entity);
    }

    @Override
    public int edit(SysCourseOrders entity) {
        return sysCourseOrdersMapper.update(entity);
    }

    @Override
    public int remove(Integer id) {
        return sysCourseOrdersMapper.delete(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return sysCourseOrdersMapper.deleteBatch(ids);
    }

    @Override
    public List<SysCourseOrders> find(SysCourseOrders entity) {
        List<SysCourseOrders> list = sysCourseOrdersMapper.select(entity);
        return list;
    }

    @Override
    public SysCourseOrders findById(Integer id) {
        SysCourseOrders entity = sysCourseOrdersMapper.selectById(id);
        return entity;
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, SysCourseOrders entity) {
        PageHelper.startPage(pageNum,pageSize);
        List<SysCourseOrders> list;
        list = sysCourseOrdersMapper.select(entity);
        PageInfo<SysCourseOrders> pageInfo = new PageInfo<>(list);
        HashMap<String,Object> map = new HashMap<>();
        map.put(CommonConstant.PAGE_LIST,list);
        map.put(CommonConstant.PAGE_TOTAL,pageInfo.getPages());
        map.put(CommonConstant.TOTAL,pageInfo.getTotal());
        return map;
    }

    @Override
    public Map<String, Object> findByName(Integer pageNum, Integer pageSize, String username, String courseName) {
        System.out.println(username);
        System.out.println(courseName);
        PageHelper.startPage(pageNum,pageSize);
        List<SysCourseOrders> list;
        list = sysCourseOrdersMapper.selectByName(username,courseName);
        PageInfo<SysCourseOrders> pageInfo = new PageInfo<>(list);
        HashMap<String,Object> map = new HashMap<>();
        map.put(CommonConstant.PAGE_LIST,list);
        map.put(CommonConstant.PAGE_TOTAL,pageInfo.getPages());
        map.put(CommonConstant.TOTAL,pageInfo.getTotal());
        return map;
    }
}
